home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_10_01 / cips1001.exe / DISPLAY.C < prev    next >
C/C++ Source or Header  |  1991-04-27  |  20KB  |  834 lines

  1.  
  2.        /*****************************************************
  3.        *
  4.        *       file d:\cips\display.c
  5.        *
  6.        *       Functions: This file contains
  7.        *          display_image
  8.        *          display_image_portion
  9.        *          display_menu_for_display_image
  10.        *          map_16_shades_of_gray
  11.        *          transform_the_colors
  12.        *
  13.        *       Purpose:
  14.        *          These functions display images on a the
  15.        *          monitor.
  16.        *
  17.        *       External Calls:
  18.        *          rtiff.c - read_tiff_image
  19.        *          cips.c - clear_text_screen
  20.        *          hist.c - zero_histogram
  21.        *                   calculate_histogram
  22.        *                   perform_histogram_equalization
  23.        *
  24.        *       Modifications:
  25.        *          17 June 1987 - created
  26.        *          August 1990 - extension modifications for use
  27.        *              in the C Image Processing System.
  28.        *
  29.        ********************************************************/
  30.  
  31.  
  32. #include "d:\cips\cips.h"
  33.  
  34.  
  35.  
  36.  
  37.  
  38.    /***************************
  39.    *
  40.    *   display_image(...
  41.    *
  42.    ****************************/
  43.  
  44.  
  45. display_image(file_name, image, il, ie, ll, le,
  46.               image_header, monitor_type, color_transform,
  47.               invert, image_colors, display_colors,
  48.               show_hist)
  49.    char    color_transform[],
  50.            file_name[],
  51.            monitor_type[];
  52.    int     display_colors,
  53.            image_colors,
  54.            invert,
  55.            il,
  56.            ie,
  57.            ll,
  58.            le,
  59.        show_hist;
  60.    short   image[ROWS][COLS];
  61.    struct  tiff_header_struct *image_header;
  62. {
  63.    char  channels[80],
  64.          response[80];
  65.  
  66.    int   a,
  67.          b,
  68.          c,
  69.          channel,
  70.          count,
  71.          display_mode,
  72.          key,
  73.          horizontal,
  74.          max_horizontal,
  75.          max_vertical,
  76.          not_finished,
  77.          q,
  78.          r,
  79.          vertical,
  80.          x_offset,
  81.          y_offset;
  82.  
  83.    unsigned int block,
  84.                 color,
  85.                 i,
  86.                 j,
  87.                 x,
  88.                 y;
  89.  
  90.    unsigned long histogram[256], new_hist[256];
  91.  
  92.  
  93.      /*************************************************
  94.      *
  95.      *   If you want to display the histogram and do not
  96.      *   want to perform hist equalization, then
  97.      *   zero the histogram for calculations.
  98.      *
  99.      *************************************************/
  100.  
  101.    if(  (show_hist == 1)   &&
  102.         (color_transform[0] != 'H'))
  103.       zero_histogram(histogram);
  104.  
  105.    not_finished = 1;
  106.    while(not_finished){
  107.  
  108.  
  109.       if(display_colors == 16){
  110.          if(monitor_type[0] == 'V'){
  111.             horizontal   = 4;
  112.         vertical = 6;
  113.         display_mode = _VRES16COLOR; /* MSC 6.0 */
  114.          }  /* ends if V */
  115.          if(monitor_type[0] == 'E'){
  116.             horizontal   = 3;
  117.             vertical     = 6;
  118.             display_mode = _ERESCOLOR; /* MSC 6.0 */
  119.          }  /* ends if E */
  120.  
  121.       }  /* ends if colors == 16 */
  122.  
  123.       else{
  124.          horizontal   = 2;
  125.          vertical     = 2;
  126.          display_mode = _MAXCOLORMODE; /* MSC 6.0 */
  127.       }
  128.  
  129.  
  130.       max_horizontal = (image_header->image_length+50)/100;
  131.       max_vertical   = (image_header->image_width+50)/100;
  132.  
  133.       if(horizontal > max_horizontal) horizontal = max_horizontal;
  134.       if(vertical > max_vertical) vertical = max_vertical;
  135.  
  136.  
  137.  
  138.         /****************************************
  139.         *
  140.         *   If color transform wants histogram
  141.         *   equalization, then read in the
  142.         *   image arrays and calculate the
  143.         *   histogram.   Zero both the histogram
  144.         *   and the new_hist.  You will need the
  145.         *   new_hist if you want to display the
  146.         *   equalized hist.
  147.         *
  148.         *****************************************/
  149.  
  150.       if(color_transform[0] == 'H'){
  151.          count = 1;
  152.          zero_histogram(histogram);
  153.          zero_histogram(new_hist);
  154.          for(a=0; a<vertical; a++){
  155.             for(b=0; b<horizontal; b++){
  156.  
  157.                x = a*100;
  158.                y = b*100;
  159.  
  160.                printf("\nDISPLAY> Calculating histogram");
  161.                printf(" %d of %d",count,vertical*horizontal);
  162.                count++;
  163.                read_tiff_image(file_name, image, il+y,
  164.                             ie+x, ll+y, le+x);
  165.                calculate_histogram(image, histogram);
  166.  
  167.             }  /* ends loop over b */
  168.          }  /* ends loop over a */
  169.       }  /* ends if display_mode == H */
  170.  
  171.  
  172.         /* set graphics mode */
  173.  
  174.    _setvideomode(display_mode); /* MSC 6.0 */
  175.    if(display_colors == 16) map_16_shades_of_gray(display_mode);
  176.    if(display_colors == 256) map_64_shades_of_gray();
  177.  
  178.  
  179.         /****************************************
  180.         *
  181.         *   Loop over this size and
  182.         *   read and display ROWSxCOLS arrays.
  183.         *
  184.         *   If you want to show the histogram AND
  185.         *   do not want to do hist equalization
  186.         *   then calculate the hist from the
  187.         *   original image array.
  188.         *
  189.         *   If you want to do hist equalization
  190.         *   then calculate the new_hist AFTER
  191.         *   the image has been equalized by the
  192.         *   the transform_the_colors function.
  193.         *
  194.         *   NOTE: Remember that the function
  195.         *   transform_the_colors changes the
  196.         *   gray shade values in image array.
  197.         *
  198.         *****************************************/
  199.  
  200.  
  201.       for(a=0; a<vertical; a++){
  202.          for(b=0; b<horizontal; b++){
  203.  
  204.             x = a*100;
  205.             y = b*100;
  206.             read_tiff_image(file_name, image, il+y,
  207.                 ie+x, ll+y, le+x);
  208.             if(  (show_hist == 1)  &&
  209.                  (color_transform[0] != 'H'))
  210.                calculate_histogram(image, histogram);
  211.  
  212.             transform_the_colors(image, color_transform,
  213.                                  display_colors,
  214.                                  image_colors, histogram,
  215.                                  horizontal, vertical);
  216.  
  217.             if(color_transform[0] == 'H')
  218.                calculate_histogram(image, new_hist);
  219.             display_image_portion(image, x, y, display_colors,
  220.                                   image_colors, invert);
  221.          }        /* ends loop over b */
  222.       }        /* ends loop over a */
  223.  
  224.  
  225.          /***************************
  226.          *
  227.          *   if show_hist == 1 then
  228.          *   display the histogram
  229.          *   in the lower right hand
  230.          *   corner of screen
  231.          *
  232.          *   If hist equalization was
  233.          *   performed then show the
  234.          *   new_hist.  If it wasn't
  235.          *   done then show the original
  236.          *   histogram.
  237.          *
  238.          ****************************/
  239.  
  240.       if(show_hist == 1){
  241.          if(monitor_type[0] == 'V')
  242.             y_offset = 470;
  243.          if(monitor_type[0] == 'E')
  244.             y_offset = 310;
  245.          x_offset = 380;
  246.          if(color_transform[0] == 'H')
  247.             display_histogram(new_hist, x_offset,
  248.                    y_offset, 10, 15);
  249.          else
  250.             display_histogram(histogram, x_offset,
  251.                    y_offset, 10, 15);
  252.       }
  253.  
  254.       read_string(response);
  255.       printf("\nEnter 0 to quit 1 to do again");
  256.       get_integer(¬_finished);
  257.  
  258.           /* set display back to text mode */
  259.       clear_text_screen();
  260.  
  261.  
  262.    }  /* ends while not_finished  */
  263.  
  264. }  /* ends main  */
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.    /***********************************************
  272.    *
  273.    *   display_menu_for_display_image(
  274.    *
  275.    ************************************************/
  276.  
  277.  
  278. display_menu_for_display_image(image_colors, display_colors,
  279.                               invert, color_transform,
  280.                               monitor_type,
  281.                               show_hist)
  282.    char color_transform[], monitor_type[];
  283.    int  *invert, *image_colors, *display_colors, *show_hist;
  284. {
  285.    char response[80];
  286.    int  int_response, not_finished, r;
  287.  
  288.    not_f